package cn.zhengzhou.springbootmybatis.demo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Account {
    private String name;
    private int money;


    public synchronized void drawMoney(double money) {
        String name = Thread.currentThread().getName();

//        synchronized (this) {
            if (this.money >= money) {
                System.out.println(name + "取钱成功，取出" + money + "元");
                this.money -= money;
                System.out.println(name + "取钱成功，还剩余" + this.money + "元");
            } else {
                System.out.println(name + "余额不足");
            }

//        }
    }

}
